import {Dialog} from "vant";
import OnlineAPI from "../../repo/api/OnlineAPI";
import store from "../../repo/store/store";

const buyToast = (planDetail,callback) =>{
  OnlineAPI.getParam().then((result) => {
    let hsId = store.getters.hsId
    let data = result.planToast
    console.log(data)
    let status = 0
    if(data[hsId]){
      let planList = data[hsId].planIds
      let content = data[hsId].content
      let meta = data.meta

      planList.forEach((planId) => {
        if (planDetail.id == planId) {
          status = 1
          Dialog.alert({
            title: meta,
            message: content,
            width: '330px',
            messageAlign: 'left',
            confirmButtonText: '确定',
            showCancelButton: true
          }).then((result) =>{
            callback(1)
          }).catch(() =>{
            console.log("点击了取消按钮")
          })
        }
      })
    }
    if(status == 0){
      callback(0)
    }
  })
}
export default {
  buyToast,
}
